package com.pmsystem.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pmsystem.pojo.Accident;
import com.pmsystem.pojo.SecurityArea;
import com.pmsystem.pojo.SecurityMan;
import com.pmsystem.pojo.SecurityMis;
import com.pmsystem.service.SecurityService;



@Controller
@RequestMapping("security")
public class SecurityController {

	@Autowired
	SecurityService securityService;
	
	/**
	 * <p>Title: index</p >  
	 * <p>Description: 主页路径</p >  
	 * @author 魏家洛
	 * @param mv
	 * @return
	 */
	
	@RequestMapping("index")
	public String index(ModelAndView mv) {
		return "security/security_index";
	}
	
	
	//安保区域操作
		/**
		 * <p>Title: findAreaPage</p >  
		 * <p>Description:传入页码和页大小获取页码对应保洁区域信息</p >  
		 * @author 魏家洛
		 * @param pageNo
		 * @param pageSize
		 * @return
		 */
		@RequestMapping("findareapage")
		@ResponseBody
		public Map findAreaPage(Integer pageNo,Integer pageSize,String condition){
			return securityService.findAreaPage(pageNo,pageSize,condition);
		}
		/**
		 * <p>Title: deletesecurity</p >  d
		 * <p>Description:删除保洁区域信息</p >  
		 * @author 魏家洛
		 * @param id
		 * @return
		 */
		@RequestMapping("deletearea")
		@ResponseBody
		public boolean deleteArea(Integer id){
			return securityService.deleteArea(id);
		}
		/**
		 * <p>Title: updateArea</p >  
		 * <p>Description: 更新保洁区域信息</p >  
		 * @author 魏家洛
		 * @param id
		 * @param mv
		 * @return
		 */
		@RequestMapping("updatearea")
		public ModelAndView updateArea(Integer id,ModelAndView mv){
			mv.addObject("securityArea",securityService.selectArea(id));
			mv.setViewName("security/security_area");
			return mv;
		}
		@RequestMapping("updatearea1")
		public String updateArea1(SecurityArea securityArea){
			securityService.updateArea(securityArea);
			return "redirect:index#area";
		}
		/**
		 * <p>Title: addArea</p >  
		 * <p>Description: 添加安保区域信息</p >  
		 * @author 魏家洛
		 * @param securityAreaName
		 * @return
		 */
		@RequestMapping("addarea")
		public String addArea(String securityAreaName){
			securityService.addArea(securityAreaName);
			return "redirect:index#area";
		}
	
	
	//安保人员操作
	/**
	 * <p>Title: findManPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应安保人员信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findmanpage")
	@ResponseBody
	public Map findManPage(Integer pageNo,Integer pageSize,String condition){
		return securityService.findManPage(pageNo,pageSize,condition);
	}
	/**
	 * <p>Title: deleteMan</p >  
	 * <p>Description:删除安保人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deleteman")
	@ResponseBody
	public boolean deleteMan(Integer id){
		return securityService.deleteMan(id);
	}
	/**
	 * <p>Title: updateMan</p >  
	 * <p>Description: 更新安保人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("updateman")
	public ModelAndView updateMan(Integer id,ModelAndView mv){
		mv.addObject("securityMan",securityService.selectMan(id));
		mv.setViewName("security/update_man");
		return mv;
	}
	@RequestMapping("updateman1")
	public String updateMan1(SecurityMan securityMan){
		securityService.updateMan(securityMan);
		return "redirect:index#man";
	}
	/**
	 * <p>Title: addMan</p >  
	 * <p>Description: 添加安保人员信息</p >  
	 * @author 魏家洛
	 * @param securityMan
	 * @return
	 */
	@RequestMapping("addman")
	public String addMan(SecurityMan securityMan){
		securityService.addMan(securityMan);
		return "redirect:index#man";
	}
		
		
		
	//安保任务操作
	/**
	 * <p>Title: findMisPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应安保任务信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findmispage")
	@ResponseBody
	public Map findMisPage(Integer pageNo,Integer pageSize,String condition,String startTime,String endTime){
		return securityService.findMisPage(pageNo,pageSize,condition,startTime,endTime);
	}
	/**
	 * <p>Title: deleteMis</p >  
	 * <p>Description:删除安保任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deletemis")
	@ResponseBody
	public boolean deleteMis(Integer id){
		return securityService.deleteMis(id);
	}
	/**
	 * <p>Title: updateMis</p >  
	 * <p>Description: 更新安保任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("updatemis")
	public ModelAndView updateMis(Integer id,ModelAndView mv){
		mv.addObject("securityMis",securityService.selectMis(id));
		mv.setViewName("security/update_mis");
		return mv;
	}
	@RequestMapping("updatemis1")
	public String updateMis1(SecurityMis securityMis){
		securityService.updateMis(securityMis);
		return "redirect:index#mis";
	}
	/**
	 * <p>Title: addMis</p >  
	 * <p>Description: 添加安保任务信息</p >  
	 * @author 魏家洛
	 * @param securityMis
	 * @return
	 */
	@RequestMapping("addmis")
	public String addMis(SecurityMis securityMis){
		securityService.addMis(securityMis);
		return "redirect:index#mis";
	}
	/**
	 * <p>Title: getProgress</p >  
	 * <p>Description:获取当天任务进度</p >  
	 * @author 魏家洛
	 * @return
	 */
	@RequestMapping("getprogress")
	@ResponseBody
	public int getProgress(String currentDate) {
		return securityService.getProgress(currentDate);
	}	
	
	
	//重大事件
	/**
	 * <p>Title: findAccidentPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应重大事件信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findaccidentpage")
	@ResponseBody
	public Map findAccidentPage(Integer pageNo,Integer pageSize,String condition,String time){
		System.out.println(time);
		return securityService.findAccidentPage(pageNo,pageSize,condition,time);
	}
	/**
	 * <p>Title: deleteAccident</p >  
	 * <p>Description:删除重大事件信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deleteaccident")
	@ResponseBody
	public boolean deleteAccident(Integer id){
		return securityService.deleteAccident(id);
	}
	/**
	 * <p>Title: updateAccident</p >  
	 * <p>Description: 更新重大事件信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("updateaccident")
	public ModelAndView updateAccident(Integer id,ModelAndView mv){
		mv.addObject("accident",securityService.selectAccident(id));
		mv.setViewName("security/update_accident");
		return mv;
	}
	@RequestMapping("updateaccident1")
	public String updateaccident1(Accident accident){
		securityService.updateAccident(accident);
		return "redirect:index#acc";
	}
	/**
	 * <p>Title: addMis</p >  
	 * <p>Description: 添加重大事件信息</p >  
	 * @author 魏家洛
	 * @param accident
	 * @return
	 */
	@RequestMapping("addaccident")
	public String addAccident(Accident accident){
		securityService.addAccident(accident);
		return "redirect:index#acc";
	}
}
